# -*- coding: utf-8 -*-
from datetime import timedelta
from airflow.operators.bash import BashOperator
from jms_hi.dm.dm_ops_xyf_reverse_cancel_hi import jms_dm__dm_ops_xyf_reverse_cancel_hi
from airflow.exceptions import AirflowSkipException
import pendulum
cst = pendulum.timezone('Asia/Shanghai')
class HiRichSqlSensor(BashOperator):
    def pre_execute(self, context):
        day = cst.convert(context['ti'].execution_date) + timedelta(days=1)

        days_of_hours = ['15']

        if day.strftime('%H') not in days_of_hours:
            print(f'{day.strftime("%H")} not in {days_of_hours}, should skip')
            raise AirflowSkipException()
        else:
            print(f'{day.strftime("%H")} in {days_of_hours}, run now')
            super().pre_execute(context)


jms_oracle__dm_ops_xyf_reverse_cancel_hi = HiRichSqlSensor(
    task_id='jms_oracle__dm_ops_xyf_reverse_cancel_hi',
    execution_timeout=timedelta(hours=2),
    email=['macheng@jtexpress.com','yl_bigdata@yl-scm.com'],
    bash_command="jms_hi/oracle/dm_ops_xyf_reverse_cancel_hi/execute.sh",
    pool='spmi_apack',
    retries=1,
    pool_slots=2,
)
jms_oracle__dm_ops_xyf_reverse_cancel_hi << [jms_dm__dm_ops_xyf_reverse_cancel_hi]